const express = require('express');

const app = express();

app.get('/server', (require , response)=>{
    //设置允许跨域
    response.setHeader('Access-Control-Allow-Origin','*');
    response.send('HELLO');
});

app.post('/server', (require , response)=>{
    //设置允许跨域
    response.setHeader('Access-Control-Allow-Origin','*');
    response.send('HELLO POST');
});
app.all('/json-server', (require , response)=>{
    //设置允许跨域
    response.setHeader('Access-Control-Allow-Origin','*');
    const data = {
        name: 'lihua'
    };
    //对对象进行字符串转换
    let str = JSON.stringify(data);
    response.send(str);
});
app.get('/time', (require , response)=>{
    //设置允许跨域
    response.setHeader('Access-Control-Allow-Origin','*');
    setTimeout(() => {
        response.send('HELLO POST');

    }, 3000)
});
app.listen(8000, ()=>{
    console.log("服务已经启动");
})